﻿using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Activities;
using System.Activities.Expressions;
using System.Activities.Presentation.PropertyEditing;
using System.Activities.Statements;
using System.Collections.Generic;
using System.ComponentModel;
using Core = Vision.Core;

namespace Vision.Core.ActivityComponents.IO.File
{
    /// <summary>
    /// 
    /// </summary>
    public class DirectoryInfo : NativeActivity
    {
        /// <summary>
        /// 
        /// </summary>
        [Category("Input")]
        public InArgument<string> DirectoryPath { get; set; }
                
        /// <summary>
        /// 
        /// </summary>
        [Category("Output")]
        public OutArgument<string> Name { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [Category("Output")]
        public OutArgument<string> Root { get; set; }
        
        /// <summary>
        /// 
        /// </summary>
        [Category("Output")]
        public OutArgument<string> Parent { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [Category("Output")]
        public OutArgument<DateTime> CreationTime { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [Category("Output")]
        public OutArgument<DateTime> LastAccessTime { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [Category("Output")]
        public OutArgument<DateTime> LastWriteTime { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(NativeActivityContext context)
        {
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(this.DirectoryPath.Get(context));
            if (di != null){
                this.Name.Set(context, di.Name);
                this.Root.Set(context, di.Root.FullName);
                this.Parent.Set(context, di.Parent.FullName);
                this.CreationTime.Set(context, di.CreationTime);
                this.LastAccessTime.Set(context, di.LastAccessTime);
                this.LastWriteTime.Set(context, di.LastWriteTime);                               
                di = null;   
            }            
        }
    }
}
